package com.genia.toolbox.projects.toolbox_basics_project.web.taglib;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.genia.toolbox.projects.toolbox_basics_project.bean.model.I18nDynamicValue;
import com.genia.toolbox.projects.toolbox_basics_project.spring.manager.I18nDynamicEntityManager;

/**
 * Tag for displaying value of {@link I18nDynamicValue}.
 */
@SuppressWarnings("serial")
public class SpringI18nDynamicTag
    extends TagSupport
{

  /**
   * the {@link I18nDynamicValue}.
   */
  private I18nDynamicValue value;

  /**
   * the {@link I18nDynamicEntityManager}.
   */
  private I18nDynamicEntityManager i18DynamicEntityManager;



  /**
   * process tag for {@link I18nDynamicValue}.
   * 
   * @return an int.
   * @throws JspException
   *           exception tag.
   */
  @Override
  public int doStartTag()
      throws JspException
  {

    try {
      String value = getI18DynamicEntityManager().getTranslation(getValue());

      if (value != null) {
        pageContext.getOut().print(value);
      }
    }
    catch (Exception e) {
      throw new JspException(e);
    }
    return SKIP_BODY;
  }



  /**
   * getter for the value property.
   * 
   * @return the value
   */
  public I18nDynamicValue getValue()
  {
    return value;
  }



  /**
   * setter for the value property.
   * 
   * @param value
   *          the value to set
   */
  public void setValue(I18nDynamicValue value)
  {
    this.value = value;
  }



  /**
   * getter for the i18DynamicEntityManager property.
   * 
   * @return the i18DynamicEntityManager
   */
  public I18nDynamicEntityManager getI18DynamicEntityManager()
  {
    return i18DynamicEntityManager;
  }



  /**
   * setter for the i18DynamicEntityManager property.
   * 
   * @param dynamicEntityManager
   *          the i18DynamicEntityManager to set
   */
  public void setI18DynamicEntityManager(I18nDynamicEntityManager dynamicEntityManager)
  {
    i18DynamicEntityManager = dynamicEntityManager;
  }

}
